package rsj.api.org.importdata;

import com.rlyy.aibase.db.Dbink;
import com.rlyy.aibase.utils.base.Box;
import common.util.Assert;
import common.util.BoxUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import rsj.api.user.BaseLink;
import rsj.db.PostgresqlConn;
import common.util.QueryRunnerFactory;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * 忽略失败
 *
 * @author yuanqinglong
 * @since 2021/3/9 17:50
 */
@Deprecated
@RestController
public class IgnoreFailureController extends BaseLink {

    /**
     * 忽略失败
     *
     * @param box 参数
     * @return 响应
     */
    @Override
    @RequestMapping(value = "rsj_ignore_import_failed")
    public Box executeLink(Box box) throws SQLException {
        String logId = box.getMapNode("data").getValue("log_id");
        Assert.isNotBlank(logId, "日志id不可为空");
        Connection connection = PostgresqlConn.getConnection();
        try {
            QueryRunnerFactory.getQueryRunner().update(connection, this.ignoreSql(logId));
        } finally {
            Dbink.close(connection);
        }
        return BoxUtil.successBox(box);
    }


    /**
     * 修改忽略状态sql
     *
     * @param logId 日志id
     * @return sql
     */
    private String ignoreSql(String logId) {
        return "UPDATE sys.oper_test_fail_log SET log_is_ignore = '" + ImportEasyExcelInvoke.IGNORE + "' WHERE log_id = '" + logId + "'";
    }
}
